package com.sunday.haowushop.ui.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.sunday.haowushop.R;
import com.sunday.common.base.BaseFragment;
import com.sunday.haowushop.adapter.ShopFragmentAdapter;


import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/4/11.
 */

public class ShopManageFragment extends BaseFragment {

    @Bind(R.id.header_layout)
    RelativeLayout headerLayout;
    @Bind(R.id.shop_img)
    ImageView shopImg;
    @Bind(R.id.shop_title)
    TextView shopTitle;
    @Bind(R.id.shop_description)
    TextView shopDescription;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.collapse_toolbar)
    CollapsingToolbarLayout collapseToolbar;
    @Bind(R.id.appbar_layout)
    AppBarLayout appbarLayout;
    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shop, container, false);
        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView(){
        setUpToolbar();
        setupCollapsingToolbar();
        initAdapter();

    }

    private void setUpToolbar(){

    }

    private void setupCollapsingToolbar(){
        collapseToolbar.setTitleEnabled(true);
        appbarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (verticalOffset<=headerLayout.getHeight()){
                    collapseToolbar.setTitle("店主精选");
                }else{
                    collapseToolbar.setTitle(" ");
                }
            }
        });
    }

    private void initAdapter(){
        ShopFragmentAdapter adapter = new ShopFragmentAdapter(mContext);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
    }




    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
